//:C06:Couting.cpp
// The counting algorithms.
// {L} Generators
#include <algorithm>
#include <functional>
#include <iterator>
#include <set>
#include <vector>
#include "Generators.h"
#include "PrintSequence.h"
using namespace std;

int main(void)
{
    vector<char> v;
    generate_n(back_inserter(v), 50, CharGen());
    print(v.begin(), v.end(), "v", "");
    // Create a set of the characters in v:
    set<char> cs(v.begin(), v.end());
    typedef set<char>::iterator sci;
    for(sci it = cs.begin(); it != cs.end(); it++)
    {
        int n = count(v.begin(), v.end(), *it);
        cout << *it << ": " << n << ". ";
    }
    int lc = count_if(v.begin(), v.end(),
        bind2nd(greater<char>(), 'a'));
    cout << "\nlowercase letters: " << lc << endl;
    sort(v.begin(), v.end());
    print(v.begin(), v.end(), "sorted", "");
}